import { ProTableColumn } from '@/components/pro-table/type'
import { AnomalyModel } from '@/api/model/anomalyModel'
import { NCode } from 'naive-ui'

export const useAnomalyProTable = () => {
  const columns: ProTableColumn<AnomalyModel>[] = [
    {
      title: '所属三方系统',
      key: 'thirdSystem',
      align: 'center',
      width: 120
    },
    {
      title: '请求地址',
      key: 'url',
      align: 'center',
      width: 120
    },
    {
      title: '请求体内容',
      key: 'requestBody',
      align: 'center',
      render(row, index) {
        return (
          <NCode
            code={JSON.stringify(JSON.parse(row.requestBody), null, 2)}
            language={'json'}
            word-wrap={true}
            style={{ fontSize: '12px' }}
          />
        )
      }
    },
    {
      title: '响应内容',
      key: 'responseBody',
      render(row, index) {
        return (
          <NCode
            code={JSON.stringify(JSON.parse(row.requestBody), null, 2)}
            language={'json'}
            word-wrap={true}
            style={{ fontSize: '12px' }}
          />
        )
      }
    },
    {
      title: '请求耗时（毫秒）',
      align: 'center',
      key: 'elapsedTime',
      width: 150
    },
    {
      title: '状态码',
      key: 'status',
      align: 'center',
      type: 'tag',
      width: 120,
      dictOptions: [
        {
          value: '200',
          label: '200',
          type: 'success'
        },
        {
          value: '401',
          label: '401',
          type: 'error'
        },
        {
          value: '403',
          label: '403',
          type: 'error'
        },
        {
          value: '404',
          label: '404',
          type: 'error'
        },
        {
          value: '500',
          label: '500',
          type: 'error'
        }
      ]
    }
  ]

  return {
    columns
  }
}
